<?php

class Auto_AllApp_Page_MoveData extends Auto_AllApp_Page_Abstract
{
    protected $_dbAdmin;
    public function loadDb(){
        $this->_dbAdmin     = Db_Admin::instance();
    }
    public function doDefault(ME_Request $input){
        echo "test";
        exit;
    }
    public function doDataRans(ME_Request $input)
	{
        $this->loadDb();
        $sql = "select id ,title from cms_document_title_1  where status = 0 ";
        $data = $this->_dbAdmin->getAll($sql);
        if($data){
            foreach($data as $d){
                echo $d['title'];
                $addStr = '周公解梦关于<strong>梦见'.$d['title'].'</strong>的解释：<br />';
                $usql = "update cms_document_content_1 set content = CONCAT('{$addStr}', content) where documentId = ".$d['id'];
                $this->_dbAdmin->query($usql);
            }
        }
        echo "ok";
        exit;
        
    }
    //转换成拼音
    public function doPinyin(ME_Request $input){

        $this->loadDb();
        $sql = "select id ,title,enfile from cms_document_title_1  where status = 0  ";//and enfile = ''
        $data = $this->_dbAdmin->getAll($sql);
        if($data){
            foreach($data as $d){
                $title = $d['title'];
                $did   = $d['id'];
                $enfile = ME_String::toPinyin($d['title'],1);

                //查看是否有已经存在                
                $sql3 = "update cms_document_title_1 set enfile ='{$enfile}' where id = {$did} limit 1";
                $this->_dbAdmin->query($sql3);
                
                echo "$title \n";
            }
        }
        echo 'ok';
        exit;
    }
    //重命名那些已经存在的
    public function doRename(ME_Request $input)
	{
        $this->loadDb();
        $sql = "select id ,title from cms_document_title_1  where status = 0 ";
        $data = $this->_dbAdmin->getAll($sql);
        if($data){
            foreach($data as $d){
                $title = $d['title'];
                $did   = $d['id'];
                //查看是否有已经存在
                $sql2 = "select 'x' from cms_document_title_1 where title ='{$title}' and status = 3 limit 1";
                $has = $this->_dbAdmin->getOne($sql2);
                if($has){
                    $sql3 = "update cms_document_title_1 set title ='{$title}(重名)',status = 1 where id = {$did} limit 1";
                    $this->_dbAdmin->query($sql3);
                }
                echo "$title \n";
            }
        }
        echo 'ok';
        exit;
    }


    //回复
    public function doCover(ME_Request $input)
	{
        $this->loadDb();
        $sql = "select id ,title from cms_document_title_1  where status = 1";
        $data = $this->_dbAdmin->getAll($sql);
        if($data){
            foreach($data as $d){
                $title = $d['title'];
                $did   = $d['id'];
                $title = str_replace('(重名)', '', $title);
                $sql3 = "update cms_document_title_1 set title ='{$title}',status = 1 where id = {$did} limit 1";
                $this->_dbAdmin->query($sql3);
                echo "$title \n";
            }

            $sql4 = "update cms_document_title_1 set status = 0 where status = 1";
            $this->_dbAdmin->query($sql4);
        }
        echo 'ok';
        exit;
    }

}
